有了Deployment並運行後
創建Horizontal Pod Autoscaler
例如,我讓她監視 nginx-deployment 的 CPU 使用率,並在 CPU 使用率達到 50% 時自動擴展 Pod 的副本數,最多擴展到 5 個副本,最少保持 1 個副本。
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: nginx-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx-deployment
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
監視自動擴展:
kubectl get hpa nginx-hpa